const Koa = require('koa')
const app = new Koa()
// koa-router 返回的是函数
const router = require('koa-router')()

// 添加路由
router.get('/', async (ctx, next) => {
  ctx.response.body = '<h1>index page</h1>'
})

router.get('/home', async (ctx, next) => {
  ctx.response.body = '<h1>home page</h1>'
})

router.get('/404', async (ctx, next) => {
  ctx.response.body = '<h1>404 Not Found</h1>'
})

// 调用路由中间件
app.use(router.routes())

app.listen(3000, () => {
  console.log('server is running at http://localhost:3000')
})